package com.lyf.scm.plan.api.controller;

import com.lyf.scm.plan.api.dto.ActualSalesQtyQueryDTO;
import com.lyf.scm.plan.domain.service.ActualSalesQtyService;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Martin
 * @date 2020-11-11 11:17
 */
@Slf4j
@RomeController
@Api(tags = "查询实际销量")
@RequestMapping("/api/v1/actualSalesQty")
public class ActualSalesQtyController {

    @Resource
    private ActualSalesQtyService actualSalesQtyService;

    /**
     * {
     *   "dateList": [
     *     "2020-10-12", "2020-10-19", "2020-10-26", "2020-11-02", "2020-11-09", "2020-11-16"
     *   ],
     *   "areaConditionList":[
     *     {
     *       "level":1,
     *       "list": ["310000"]
     *     }
     *   ],
     *   "skuList": ["11441"],
     *   "areaAggsLevel": 1,
     *   "endTime": "20201116",
     *   "startTime": "20201012",
     *   "kpChannelList": ["C00001"]
     * }
     * 根据渠道、区域、sku聚合查询实际销量
     * @param dto
     * @return
     */
    @PostMapping("/groupByChannelAreaSku")
    public Response<Map<String, List<BigDecimal>>> groupByChannelAreaSku(@RequestBody ActualSalesQtyQueryDTO dto) {
        Map<String, List<BigDecimal>> res = actualSalesQtyService.getActualDalesData(dto);
        return Response.builderSuccess(res);
    }

    /**
     * echart图查询实际销量，传dateList、startTime、endTime以及其他条件，如渠道、区域、品类、sku
     * @param dto
     * @return
     */
    @PostMapping("/groupByDate")
    public Response<List<BigDecimal>> groupByDate(@RequestBody ActualSalesQtyQueryDTO dto) {
        List<BigDecimal> res = actualSalesQtyService.getEchartActualDalesData(dto);
        return Response.builderSuccess(res);
    }

    static class OtherTargetResult {
        private String target;
        // key 渠道+区域+sku
        private Map<String, List<BigDecimal>> map;
    }

}
